package com.fangyu.lottery.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 抽奖策略工厂
 * @author fangyu
 * @version v1.0.0
 * @since 2025/8/27 23:43
 */
@Component
public class DrawStrategyFactory {
    private static Map<String, DrawStrategy> strategyMap = new HashMap<>();

    @Autowired
    public DrawStrategyFactory(
            @Qualifier("probability") DrawStrategy probabilityStrategy,
            @Qualifier("weighted") DrawStrategy weightedStrategy) {
        strategyMap.put("probability", probabilityStrategy);
        strategyMap.put("weighted", weightedStrategy);
    }

    public static DrawStrategy getStrategy(String type) {
        return strategyMap.getOrDefault(type, strategyMap.get("probability"));
    }
}